package cn.e4j.modular.crm.service.impl;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.util.InvokeUtil;
import cn.e4j.modular.crm.entity.GwcaT;
import cn.e4j.modular.crm.mapper.Gwcq001Mapper;
import cn.e4j.modular.crm.service.Gwcq001Service;
import cn.e4j.modular.erp.controller.ErpLogic;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.jsonwebtoken.lang.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 合同订单信息查询 服务实现类
 * </p>
 *
 * @author mengyb
 * @since 2019-12-10
 */
@Service
public class Gwcq001ServiceImpl extends ServiceImpl<Gwcq001Mapper, GwcaT> implements Gwcq001Service {

    @Override
    public List<Dto> getList(Page<Object> page, Dto dto) {
        //List<Dto> retList = this.baseMapper.getList(page, dto);
        /*if (!Collections.isEmpty(retList)) {
            for (Dto dtoInfo : retList) {
                dto.put("XMDAUA001", dtoInfo.getString("GWCA005"));//合同编号
                dto.put("XMDCUA005", dtoInfo.getString("GWCB002"));//车型
                dto.put("XMDCUA002", dtoInfo.getString("GWCA004"));//配置情况
                //获取出货单过账日期
                Dto xmdk001Dto = this.baseMapper.getXmdk001(dto);
                //获取已出货数量
                Dto xmdd014Dto = this.baseMapper.getXmdd014(dto);

                if (xmdk001Dto != null && xmdk001Dto.getString("XMDK001") != null) {
                    dtoInfo.put("XMDK001", xmdk001Dto.getString("XMDK001"));
                }

                if (xmdd014Dto != null && xmdd014Dto.getBigDecimal("XMDD014") != null) {
                    dtoInfo.put("XMDD014", xmdd014Dto.getBigDecimal("XMDD014"));//已发车辆
                    BigDecimal subQty = dtoInfo.getBigDecimal("GWCB006")
                            .subtract((xmdd014Dto.getBigDecimal("XMDD014")));//未发车辆
                    dtoInfo.put("XMDD014_ELSE", subQty);
                } else {
                    dtoInfo.put("XMDD014", 0);
                    dtoInfo.put("XMDD014_ELSE", dtoInfo.get("GWCB006"));
                }
            }
        }*/
        List<Dto> retList = InvokeUtil.invokeBeanMethod("gwcq001Mapper,getList", page, dto);
        return retList;
    }

    @Override
    public List<Map<String, Object>> getListData(Dto dto) {
        /*List<Map<String, Object>> retList = this.baseMapper.getList(dto);
        if (!Collections.isEmpty(retList)) {
            for (Map<String, Object> dtoInfo : retList) {
                dto.put("XMDAUA001", dtoInfo.get("GWCA005"));//合同编号
                dto.put("XMDCUA005", dtoInfo.get("GWCB002"));//车型
                dto.put("XMDCUA002", dtoInfo.get("GWCA004"));//配置情况
                //获取出货单过账日期
                Dto xmdk001Dto = this.baseMapper.getXmdk001(dto);
                //获取已出货数量
                Dto xmdd014Dto = this.baseMapper.getXmdd014(dto);

                if (xmdk001Dto != null && xmdk001Dto.getString("XMDK001") != null) {
                    dtoInfo.put("XMDK001", xmdk001Dto.getString("XMDK001"));
                }

                if (xmdd014Dto != null && xmdd014Dto.getBigDecimal("XMDD014") != null) {
                    dtoInfo.put("XMDD014", xmdd014Dto.getBigDecimal("XMDD014"));//已发车辆
                    BigDecimal subQty = new BigDecimal(dtoInfo.get("GWCB006").toString())
                            .subtract((xmdd014Dto.getBigDecimal("XMDD014")));//未发车辆
                    dtoInfo.put("XMDD014_ELSE", subQty);
                } else {
                    dtoInfo.put("XMDD014", 0);
                    dtoInfo.put("XMDD014_ELSE", dtoInfo.get("GWCB006"));
                }
            }
        }*/
        List<Map<String, Object>> retList = InvokeUtil.invokeBeanMethod("gwcq001Mapper,getList", dto);
        return retList;
    }
}
